package com.rysima.wjsima.demo.Demo1;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Demo3 {
    public static void main(String[] args) {
        /*
        1.核心线程数  int 2
        2.最大线程数 int4
        3.空闲线程最大存活时间 2
        4.时间单位   TimeUnit.SECONDS
        5.任务队列     new ArrayBlockingQueue<>(10)
        6.创建线程工厂    Executors.defaultThreadFactory()
        7.任务的拒绝策略   new ThreadPoolExecutor.AbortPolicy()
         */
        ThreadPoolExecutor pool = new ThreadPoolExecutor(2,4,2, TimeUnit.SECONDS,new ArrayBlockingQueue<>(10), Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
        pool.submit(() -> {
            System.out.println(Thread.currentThread().getName() + "执行了");
        });
        pool.submit(() -> {
            System.out.println(Thread.currentThread().getName() + "执行了");
        });
        pool.shutdown();
    }
}
